package com.cy;

import org.apache.catalina.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ScaProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(ScaProviderApplication.class,args);
    }

    //服务提供方
    @Value("${server.port}")//读取application.yml中的server.port
    private String server;
    @RefreshScope  //动态刷新配置文件
    @RestController
    public class ProviderController{
        public ProviderController(){
            System.out.println("ProviderController");
        }
        //logging.level.com.cy:debug 冒号后面加一个默认值没有拿到配置文件的值就为默认值
        @Value("${logging.level.com.cy:error}")
        private String logLevel;

        //使用该属性来读取
        @Value("${server.tomcat.threads.max:200}")
        private String maxThreads;

        @Value("${page.pageSize:10}")
        private Integer pageSize;

        @GetMapping("/provider/doGetPageSize")
        public String doGetPageSize(){
            return "page size is "+pageSize;
        }
        //使用该方法来呈现在页面
        @GetMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){
            return "tomcat max thread is "+maxThreads;
        }
        @GetMapping("doGetLogLevel")
        public String doGetLogLevel(){
            return "log level is "+ logLevel;
        }
        @GetMapping("/provider/echo/{msg}")
        public String doEcho(@PathVariable String msg){
            return server+"say hello " + msg;
        }
    }
}
